多图片生成PDF(一)多图片生成HTML

您所在的位置:网站首页 html 生成 pdf 多图片生成PDF(一)多图片生成HTML

多图片生成PDF(一)多图片生成HTML

2024-07-10 10:00:56| 来源: 网络整理| 查看: 265

多图片生成HTML 一、准备前提 1、准备一个html模板

pdf ###image_list###

2、准备CSS模板(css模板网上找的)

@page { size: 10.42in 8.12in; margin: 0; content: counter(page); width: 100%; height: 100%; } /*不能随意修改这里 hongwei.lian*/ html, body { margin: 0; } ul, ol, li, img { margin: 0; padding: 0; } li { list-style-type: none; } .box { width: 100%; position: relative; } img { width: 100%; } .content-box { position: absolute; top: 230px; left: 100px; bottom: 150px; right: 30px; } .order-track .track-list { margin: 20px 10px; /* max-height: 300px; */ padding-left: 5px; /* overflow-y: auto; */ position: relative; } .box-track .track-list li:first-child { padding-top: 0; } .order-track .track-list li:first-child { padding-top: 0; } .order-track .track-list li { position: relative; padding: 9px 10px 0 15px; line-height: 22px; border-left: 1px solid #d9d9d9; color: #333; font-size: 0; } .order-track .track-list li:first-child .node-icon { background-position: 0 0; height: 20px; top: 0; } .order-track .track-list li .node-icon { position: absolute; left: -6px; top: 50%; width: 11px; height: 11px; background: url("../img/order-track.png") -21px -8px #fff no-repeat; } .order-track .track-list li:first-child .date { border-left-color: #fff; } .order-track .track-list li .date { display: inline-block; width: 150px; color: #333; border-radius: 14px; font-size: 14px; text-align: left; } .order-track .track-list li:first-child .txt { font-weight: 600; } .order-track .track-list li .txt { font-size: 14px; max-width: 80%; padding-left: 10px; } .order-track .track-list li .time, .order-track .track-list li .txt { position: relative; display: inline-block; } .box-track .track-list .name { float: right; vertical-align: top; font-size: 14px; max-width: 80%; margin-right: 10px; }

二、Java代码

import cn.qcdoc.common.core.exception.BaseException; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; /** * Html * * @author: wx * @date: 2022/12/08 */ public class HtmlDemo { public static String MakeHtml(List listPath, String distPath, String templatePath){ String fileame = "test.html"; try { String templateContent = ""; // 读取模板文件 FileInputStream fileinputstream = new FileInputStream(templatePath); int length = fileinputstream.available(); byte bytes[] = new byte[length]; fileinputstream.read(bytes); fileinputstream.close(); templateContent = new String(bytes); StringBuilder sbPath = new StringBuilder(); for (String path : listPath) { String imgs = ""+"\n"+"\n" + "\t\t"; sbPath.append(imgs); } String str = sbPath.toString().replace("\\", "/"); //把模板页面上的 ###image_list### 替换成 img 里的内容 templateContent = templateContent.replaceAll("###image_list###", str); // 生成的html文件保存路径。 fileame = distPath + fileame; // 建立文件输出流 FileOutputStream fileoutputstream = new FileOutputStream(fileame); byte tag_bytes[] = templateContent.getBytes(); fileoutputstream.write(tag_bytes); fileoutputstream.close(); } catch (Exception e) { throw new BaseException("创建html失败!"); } return fileame; } public static void main(String[] args) throws Exception { List listPath = new ArrayList(); listPath.add("1665989812537.jpg"); listPath.add("1665989815178.jpg"); String distPath = "upload\\depot\\electronic\\23335\\NJ01TYQABYM\\"; String templatePath = "upload\\depot\\table.html"; MakeHtml(listPath,distPath,templatePath); } }

生成示例入下图: html代码:

总结: 以上生成HTML是基于本地生成,html里面的路径要写正常,否则打开html不会显示图片

接下来,将根据生成好的HTML生成PDF



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭